package com.leetcode.algorithm.y22.m07;

/**
 * 409. 最长回文串
 * 
 * https://leetcode.cn/problems/longest-palindrome/
 * 
 * @author jie.deng
 *
 */
class Question0409Solution01 {

	public int longestPalindrome(String s) {
		int len = s.length();
		int[] arr = new int[52];
		for (int i = 0; i < len; i++) {
			char ch = s.charAt(i);
			if (ch >= 'a') {
				arr[26 + ch - 'a']++;
			} else {
				arr[ch - 'A']++;
			}
		}

		int cnt = 0;
		int sum = 0;
		for (int i = 0; i < 52; i++) {
			if (arr[i] >= 2) {
				if ((arr[i] & 1) == 0) {
					cnt += arr[i];
				} else {
					cnt += (arr[i] - 1);
				}
			}
			sum += arr[i];
		}
		return cnt == sum ? cnt : cnt + 1;
	}

}